package day0401;

import java.util.*;

public class A03HashCodeDemo02 {
    public static void main(String[] args) {
        // define a arrays
        String[] arr = {"a", "b", "c", "d"};
        ArrayList<String> arrayList1 = new ArrayList<>();
        Random random = new Random();
        for (int i = 0; i < 80; i++) {
            int index = random.nextInt(arr.length);
            arrayList1.add(arr[index]);
        }
        // if there more than one element
        HashMap<String, Integer> hashMap1 = new HashMap<>();
        for (String name : arrayList1) {
            if(hashMap1.containsKey(name)) {
                int count=hashMap1.get(name);
                count++;
                hashMap1.put(name, count);
            }else{
                hashMap1.put(name,1);
            }
        }
        System.out.println(hashMap1);
        int max =0;
        Set<Map.Entry<String, Integer>> entries =hashMap1.entrySet();
        for (Map.Entry<String, Integer> entry : entries){
            int count = entry.getValue();
            if (count>max){
                max = count;
            }
        }
        System.out.println(max);
        for (Map.Entry<String, Integer> entry : entries){
            int count = entry.getValue();
            if (count==max){
                System.out.println(entry.getKey());
            }
        }
    }
}
